﻿
<%@ Page language="c#" Inherits="Mysoft.Crm.Application.Pages.Tools.FormEditor.Dialogs.Event" CodeBehind="Mysoft.Crm.Application.Pages.Tools.dll" %>
<%@ Register TagPrefix="cnt" Namespace="Mysoft.Crm.Application.Controls" Assembly="Mysoft.Crm.Application.Components" %>
<html>
<head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312"/>
<title>事件细节：更改事件</title>
<link rel="stylesheet" type="text/css" href="/_common/styles/global.css">
<link rel="stylesheet" type="text/css" href="/_nav/tabs.css">
<link rel="stylesheet" type="text/css" href="/Tools/FormEditor/Styles/dialogs.css">
<link rel="stylesheet" type="text/css" href="/_tools/fieldselect/fieldselect.css">
<script language="javascript" src="/_controls/settings.aspx"></script>
<script language="javascript" src="/_common/scripts/global.js"></script>
<script language="javascript" src="/Tools/FormEditor/Scripts/objects.js"></script>
<script language="javascript" src="/Tools/FormEditor/Scripts/events.js"></script>
<script language="javascript" src="/Tools/FormEditor/Scripts/fielddialogs.js"></script>
<script language="JavaScript" src="/_tools/fieldselect/fieldselect.js"></script>
<script language="JavaScript">

	var _oEvent;
	
	function window.onload()
	{
		var _oFormXml		= window.dialogArguments.FormXml;
		var _oPropertiesXml = window.dialogArguments.PropertiesXml;
		
		_oEvent	= window.dialogArguments.Event;

		crmDialog.enableScript.checked	= _oEvent.Active;
		
		// unencode 
		//
		crmDialog.scriptBody.value = _oEvent.Script
		crmDialog.scriptBody.value = crmDialog.scriptBody.value.replace(/&amp;/g, "&");
		crmDialog.scriptBody.value = crmDialog.scriptBody.value.replace(/&lt;/g, "<");
		crmDialog.scriptBody.value = crmDialog.scriptBody.value.replace(/&gt;/g, ">");

		// set the global variables for the field select object for our dialog
		//
		_iFieldSelectWidth		= 140;
		_iFieldSelectHeight		= 120;
		_sFieldSelectLeftTitle	=  "可用字段" ;
		_sFieldSelectRightTitle	=  "依赖字段" ;
		_bFieldSelectShowUp		= false;
		_bFieldSelectShowDown	= false;

		var oNodes		= _oFormXml.selectNodes("/entity/form/tabs/tab/sections/section/rows/row/cell[@name]"); 
		var iLen		= oNodes.length;

		var sFieldsXml	= "<fields>";
		var sDependsXml	= "<fields>"; 
		var sNodeName	= "";
		
		var sFieldsAry		= new Array(iLen);
			sFieldsAry[0]	= new Array(iLen);
			sFieldsAry[1]	= new Array(iLen);

		for (var i = 0; i < iLen; i++)
		{
			sNodeName = oNodes[i].getAttribute('name');
			
			sFieldsAry[0][i] = sNodeName;
			sFieldsAry[1][i] = _oPropertiesXml.selectSingleNode("/entity/fields/field[@name='" + sNodeName + "']/displaynames/displayname[@languagecode = " + ORG_LANGUAGE_CODE + "]").getAttribute("description");
			
		}

		// sort the list alphabetically by Display name -- Bug #6208
		Quicksort( sFieldsAry[1], 0, sFieldsAry[0].length - 1, sFieldsAry[0] );
		
		if (_oEvent.Dependencies)
		{
			iLen = _oEvent.Dependencies.length;
		}
		else
		{
			iLen = 0;
		}

		var sDependsName = "";

		var sDependsAry = new Array(iLen);
		sDependsAry[0] = new Array(iLen);
		sDependsAry[1] = new Array(iLen);
		
		for (var i = 0; i < iLen; i++)
		{
			sDependsName = _oEvent.Dependencies[i];
			
			sDependsAry[0][i] = sDependsName;
			sDependsAry[1][i] = _oPropertiesXml.selectSingleNode("/entity/fields/field[@name='" + sDependsName + "']/displaynames/displayname[@languagecode = " + ORG_LANGUAGE_CODE + "]").getAttribute("description");
		}
		
		// We draw the dependencies boxes and buttons
		//
		drawFieldSelect(sFieldsAry, sDependsAry);
		

		// if we are an Application event, then disable user editting for this event
		//
		if (_oEvent.Application)
		{
			crmDialog.enableScript.disabled = true;
			crmDialog.scriptBody.disabled	= true;
			crmDialog.btnRight.disabled = true;
			crmDialog.btnLeft.disabled = true;
		}
	}

	function Ok()
	{
		// Get the dependencies and put them into an array to be passed back
		//
		var oRows	= rtnObjList.firstChild.rows;
		var iLen	= rtnObjList.firstChild.rows.length;

		var sDependsAry	= new Array();
		sDependsAry		= GetReturnList();
		
		var sScript = crmDialog.scriptBody.value;
		
		sScript = sScript.replace(/&/g, "&amp;");
		sScript = sScript.replace(/</g, "&lt;");
		sScript = sScript.replace(/>/g, "&gt;");			
		
		// Package all return values up and return them to the calling window
		//

		window.returnValue	= new EventObj(
								_oEvent.Name,
								crmDialog.enableScript.checked,
								_oEvent.Application,
								sScript,
								sDependsAry
							);

	
		window.close();
	}

	function Cancel()
	{
		window.close();
	}
	
</script>
</head>
<body>
	<form name="crmDialog">
		<input type="hidden" name="DataType">
		<input type="hidden" name="Required">
		<input type="hidden" name="OrgRequired">
		<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">
			<tr>
				<td class="header">
					<div class="header"><!-Event Detail Properties->事件细节属性</div>
					<div class="headerdesc"><!-Modify this event's detail properties.->修改事件细节属性</div>
				</td>
			</tr>
			<tr>
				<td class="main">
					<table width="100%" height="100%" cellspacing="0" cellpadding="0">
						<tr height="25">
							<td>
								<cnt:AppTabBar id="crmTabBar" runat="server"/>
							</td>
						</tr>
						<tr>
							<td>
								<div id="tab0" class="tab" >
										<table cellpadding="0" cellspacing="5" width="100%" style="table-layout: fixed;">
											<tr>
												<td>
													<input id="enableScript" name="enableScript" type="checkbox" class="checkbox">
													<label for="enableScript"><!-Event enabled->激活事件</label>
												</td>
											</tr>
											<tr>
												<td>
													<!-Enter the body of your script here. It will be called when this event is fired.->在这里键入你的脚本，它将会响应这个事件。
												</td>
											</tr>
											<tr><td>function OnChange()</td></tr>
											<tr><td>{</td></tr>
											<tr>
												<td>
													<textarea type=text cols="300" rows="5" id="scriptBody" name="scriptBody"></textarea>
												</td>
											</tr>
											<tr><td>}</td></tr>
										</table>
									<br>
								</div>
								<div id="tab1" class="tab">
									<div class="desc" style="padding-bottom: 5px;">
										<!-Add fields used by script to Dependent Fields. Fields marked Dependent cannot be removed from the form.->增加本脚本依赖的字段。不能从表单中删除标记依赖的字段。
									</div>
									<span>&nbsp;</span>
									<div id="divFieldSelect" width="100%">
									</div>
								</div>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td class="buttons">
					<button id="btnDialogOk" onclick="Ok();">确定</button>
					<span>&nbsp;</span>
					<button id="btnDialogCancel" onclick="Cancel();">取消</button>
				</td>
			</tr>
		</table>
	</form>
</body>
</html>
